<script setup lang="ts">
import CardFavorites from "@/components/communal/Card/card-favorites.vue";
import {ref, defineEmits,reactive} from "vue";
import type {IListCard} from "@/views/Student/learn/Curriculum/component/data";
import {useListCardData} from "@/views/Student/learn/Curriculum/component/data";
import {useRequest} from "vue-hooks-plus";
import {postKnowledgeBaseSelectGroup} from "@/apis/student";

const emit = defineEmits(['change'])
const pagination = reactive<IPageInfo>({
  onChange: (page: number,pageSize) => {
    pagination.pageNum = page
    pagination.pageSize = pageSize
    run()
  },
  pageNum:1,
  pageSize: 10,
  total: 0,
  hideOnSinglePage: true,
  pageSizeOptions:['10', '20', '30', '40']
});

const favorites = [
  {
    ave:'',
    name:''
  }
]

let listCardData:Array<IListCard> = useListCardData()

//  获取笔记分组
let noteGroupDataList = ref<any>([])
const { data,run,loading } = useRequest(() => postKnowledgeBaseSelectGroup({
  pageNum: pagination.pageNum,
  pageSize: pagination.pageSize
}),{
  onSuccess:((res) => {
    // console.log(res.data.list)
    noteGroupDataList.value = res.data.list
    pagination.total = res.data.total
  })
})
const handleClick = (item?:any) => {
  emit('change',item)
}
</script>

<template>
  <a-list :grid="{ gutter: 9, column: 5 }" :data-source="noteGroupDataList" :pagination="pagination" :loading="loading">
    <template #renderItem="{ item }">
      <a-list-item>
        <card-favorites
            :title="item.knowledgebaseName"
            :blurb="item.knowledgebaseIntro"
            @click="handleClick(item)"
            :label="item.knowledgebaseType"
        >
        </card-favorites>
      </a-list-item>
    </template>
  </a-list>
</template>

<style scoped lang="scss">

</style>
